package com.zky.gulimall.ware.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.zky.common.to.SkuHasStockVo;
import com.zky.common.to.mq.OrderTo;
import com.zky.common.to.mq.StockLockedTo;
import com.zky.common.utils.PageUtils;
import com.zky.gulimall.ware.entity.WareSkuEntity;
import com.zky.gulimall.ware.vo.WareSkuLockVo;

import java.util.List;
import java.util.Map;

/**
 * 商品库存
 *
 * @author zky
 * @email 574096634@qq.com
 * @date 2022-08-18 21:54:51
 */
public interface WareSkuService extends IService<WareSkuEntity> {

    PageUtils queryPage(Map<String, Object> params);

    void addStock(Long skuId, Long wareId, Integer skuNum);

    List<SkuHasStockVo> getSkuHasStock(List<Long> skuIds);

    /**
     * 锁定库存
     *
     * @param lockVo
     * @return
     */
    Boolean orderLockStock(WareSkuLockVo lockVo);

    /**
     * 库存解锁
     *
     * @param stockLockedTo
     */
    void unLockedStock(StockLockedTo stockLockedTo);


    /**
     * 库存解锁
     *
     * @param skuId
     * @param wareId
     * @param skuNum
     * @param taskDetailId
     */
    void unLockStock(Long skuId, Long wareId, Integer skuNum, Long taskDetailId);

    /**
     * 防止订单服务卡顿，导致订单状态消息一直改不了，库存消息优先到期，查订单状态时新建状态，啥也没做就消费成功，后续无法再解锁库存
     *
     * @param orderTo
     */
    void unLockedStock(OrderTo orderTo);
}

